require('./init')

var path = require('path')
var Hapi = require('hapi')
var Inert = require('inert');

var server = new Hapi.Server({
    debug: { 'request': ['error', 'uncaught'] }
})


server.connection({
    port:3333,
    host:'localhost',
    labels:['web']
})

//server.register(require('vision'),function(err){
//    if(err){throw err;}
//    server.views({
//        engines:{
//            html: hbsExtend(hbs)
//        },
//        path:'views',
//        layoutPath:'views/layout',
//        layout:'default',
//        isCached:!$$is_dev,
//        partialsPath: 'views/partials',
//        helpersPath:'views/helpers'
//    })
//})

server.state('session', {
    ttl: 24 * 60 * 60 * 1000 * 30,     // 30 days
    isHttpOnly: true
});

server.register(Inert, function () {});

server.register(require('vision'),function(err){
    if(err){throw err;}
    server.views({
        engines:{
            jade: require('jade')
        },
        path:'jade',
        layoutPath:'jade/layout',
        //layout:'default',
        isCached:!$$is_dev,
        partialsPath: 'views/partials',
        compileOptions:{/*pretty:$$is_dev*/},
        context:{
            getStatic:require('./jade/helpers/getStatic')
        }

        //helpersPath:'views/helpers'
    })
})

server.route({
    method:'GET',path:'/{param*}',
    handler:{
        directory: {
            path: './public',
            redirectToSlash: true
        }
    }
})


require('./routes')(server)


server.start(function(){
    console.log('Server running at:', server.info.uri);
})